<script src="<?= base_url()?>public/js/jquery.min.js"></script>
<div class="content-wrapper">
    <!-- 内容标题 -->
    <section class="content-header">
      <h1>
        <small>用户管理/</small> 修改密码
      </h1>
      <ol class="breadcrumb">
        <li><a href="#"><i class="fa fa-dashboard"></i> 首页</a></li>
        <li><a href="#">用户管理</a></li>
        <li class="active">修改密码</li>
      </ol>
    </section>

    <!-- 内容区 -->
    <form action="<?=base_url()?>index.php/admin/user/updatepwd/<?= $id?>" method="post" id='EditForm'>
    <section class="content">
        <div class="row">
            <div class="col-xs-12">
              <div class="box">
                <div class="box-header with-border">
                   <h3 class="box-title">基础信息</h3>
                </div>
                <div class="box-body detail-page-sy"><br>
                    <dl class="dl-horizontal">
                        <?php if('yes' != $is_admin){?>
                      <dt>原密码：</dt>
                      <dd>
                        <div class="col-xs-4 row">
                            <input type="password" name="old_password" fld='old_password'
                            style='width:245px;' value="" class="form-control">
                        </div>
                        <div style='color:red;'></div>
                      </dd>
                      <?php }?><br>
                      <dt>密码：</dt>
                      <dd>
                         <div class="col-xs-4 row">
                            <input type="password" name="user[password]" fld='password'
                            style='width:245px;' value="" class="form-control">
                        </div>
                        <div style='color:red;'></div>
                      </dd><br>
                      <dt>确认密码：</dt>
                      <dd>
                        <div class="col-xs-4 row">
                            <input type="password" name="is_password" fld='is_password'
                            style='width:245px;' value="" class="form-control">
                        </div>
                        <div style='color:red;'></div>
                      </dd><br>
                    </dl>
                </div>
                <div class="box-footer align-center">
                        <button type="button" class="btn btn-primary btn-big bg-pink" id='submitBtn'>修改</button>
                        <button type="button" class="btn btn-default btn-big" id='cancelBtn'>返回</button>
                    </div>
                <!-- /.box-body -->
              </div>
            </div>
            <!-- /.col -->
          </div>
    </section>
    </form>
</div>
<script>
$(function(){
    var is_submit = 1;
    $('#submitBtn').on('click',function(){
        var idx = 1;
        if($('#EditForm input[fld=password]').val() == ''){
            $('#EditForm input[fld=password]').parent().next().html('请输入密码。');
            idx = 0;
        }else{
            $('#EditForm input[fld=password]').parent().next().html('');
        }
        if($('#EditForm input[fld=is_password]').val() == ''){
            $('#EditForm input[fld=is_password]').parent().next().html('请输入确认密码。');
            idx = 0;
        }else{
            $('#EditForm input[fld=is_password]').parent().next().html('');
        }
        if($('#EditForm input[fld=old_password]').length > 0){
            if($('#EditForm input[fld=old_password]').val() == ''){
                $('#EditForm input[fld=old_password]').parent().next().html('请输入原密码。');
                idx = 0;
            }else{
                $('#EditForm input[fld=old_password]').parent().next().html('');
            }
        }
        if(0 == idx){
            return false;
        }
        if($('#EditForm input[fld=password]').val() != $('#EditForm input[fld=is_password]').val()){
            $('#EditForm input[fld=password]').parent().next().html('密码和确认密码不一致。');
            return false;
        }else{
            $('#EditForm input[fld=password]').parent().next().html('');
        }
        if(1 != is_submit){
            return false;
        }
        is_submit = 2;
        $('#EditForm').submit();

    });
    $('#cancelBtn').on('click',function(){
        location.href = '../index';
    });
    var error_code = "<?= (isset($error_code)?$error_code:'')?>";
    if(error_code != ''){
        if($('#EditForm input[fld=old_password]').length > 0){
            $('#EditForm input[fld=old_password]').parent().next().html(error_code);
        }else{
            $('#EditForm input[fld=password]').parent().next().html(error_code);
        }
    }
});
</script>
